<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>二维码，取票码取票页面</title>
<link rel="stylesheet" href="${ctx}/static/plug/weui/css/weui.css"
	media="all">

<link rel="stylesheet" href="${ctx}/static/plug/weui/css/weuix.css"
	media="all">
	
	<link rel="stylesheet" href="${ctx}/static/css/PC/checkCodePick.css"
	media="all">
<style type="text/css">
.weui-label{
	width: 140px;
}
</style>



</head>
<body>
	<div class="header">
		
		<div class="datetime">
			<span class="times"></span>
		</div>
	</div>
		<p align="center">请刷二维码，身份证或或手动输入</p>
	<div class="subjects">
		<div id="ticket_purchase">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">取票码（身份证）</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="请输入取票码" type="number" id="checkCode" maxlength="18
            ">
        </div>
    </div>
		
		</div>
	</div>
		<p align="center" id="manual">提交信息</p>
	
	<div class="tailer">
		<div class="returns">
			<p>返回上一步</p>
		</div>
	</div>
	
</body>












<script src="${ctx}/static/js/jquery/jquery-3.2.1.min.js"></script>
<script src="${ctx}/static/js/common.js"></script>
<script src="${ctx}/static/js/aes.js"></script>
<script src="${ctx}/static/plug/weui/js/zepto.weui.js"
	type="text/javascript"></script>
<script src="${ctx}/static/plug/weui/js/zepto.min.js"
	type="text/javascript"></script>


<script>
 var orderId = 0;
	$(function() {
		
		webSocketConnect();
		function webSocketConnect() {
			var serverIP = localStorage.serverIP;
	   		var serverPort = localStorage.serverPort;
	   		var host = "ws://" + serverIP + ":" + serverPort + "/"
	        socket = new WebSocket(host);
	   	 	try {
           	  socket.onopen = function (msg) {
	               console.log(msg
	            		   )
            	};
              socket.onmessage = function (msg) {
                if (typeof msg.data == "string") {
                		var data = $.parseJSON(msg.data);
                		console.log(data)
                		console.log(msg.data)
						if(data.code == "001"){
							console.log(data.data);
							var deviceId = data.device_id;
							localStorage.deviceNo = deviceId;
                			var resultStr =  data.data.qrcode;
                			uuid = resultStr;
                			var params = {
        							"deviceNo" : localStorage.deviceNo ,
        							"uuid" : uuid 
        					}
                			params = aesHex(JSON.stringify(params));
        					$.post("${ctx}/pc/automatic/getCheckCode",{"params" : params}  , function(obj) {
        						if(obj.result){
        							$("#checkCode").val(obj.shortQrcode.checkCode);
        							return
        						}else{
        							$.alert("无效二维码！","提示",function(){});
        						}
        						
        					});	  
                		}
                		
                		if(data.code == "002"){
							var deviceId = data.device_id;
							var resultStr = data.data;
							console.log(resultStr);
							var name = resultStr.name;
							var idNumber = resultStr.cid;
							$("#checkCode").val(idNumber);
                		}
	                }
	                else {
	                    alert("非文本消息");
	                }
            	};
              socket.onclose = function (msg) { 
            	  $.confirm("连接设备失败是否继续连接", "提示", function() {
              		 webSocketConnect();
                   }, function() {
                       //取消操作
                   });
           		  };
        	}catch (ex) {
	            log(ex);
	            webSocketConnect();
        	}
		};
		
		function aesHexDecrypt(src) {
			var key = CryptoJS.enc.Utf8.parse("fb18fc197e644d38");
			console.log(src)
			console.log(CryptoJS.enc.Utf8.parse(src))
			var encryptedBase64Str = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(src));
			console.log(encryptedBase64Str)
		    var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
		    	mode: CryptoJS.mode.ECB,
			    padding: CryptoJS.pad.Pkcs7
		    });
			console.log(decryptedData)
		    var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
			console.log(decryptedStr)
			return decryptedStr;
		}
		
		
		$(".returns").click(function() {
			window.location.href="${ctx}/pc/automatic/index";
		});
		
		getNowFormatDate();
		$("#manual").click(function() {
			var codeVal = $("#checkCode").val();
			console.log(codeVal);
			console.log(codeVal.length);
			if(codeVal.length == 8 ){
				params = {
						"checkCode" :  codeVal ,
						"deviceNo" : localStorage.deviceNo
				}
				params = aesHex(JSON.stringify(params));
				window.location.href="${ctx}/pc/pickUp/checkCodePick?params=" + params;
				 return;
			}
			if(codeVal.length == 18 ){
				params = {
						"idNumber" :  codeVal,
						"deviceNo" : localStorage.deviceNo
				}
				params = aesHex(JSON.stringify(params));
				window.location.href="${ctx}/pc/pickUp/idNumPick?params=" + params;
				 return;
			}
			$.toast("输入不正确", "forbidden");
		});
		
		
		
	});
	function getNowFormatDate() {
	    var date = new Date();
	    var seperator1 = "-";
	    var seperator2 = ":";
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    var secondStr = date.getSeconds();
		var minuteStr = date.getMinutes();
		var hourStr = date.getHours();
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 0 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    if (secondStr >= 0 && secondStr <= 9) {
			secondStr = "0" + secondStr;
		}
		if (minuteStr >= 0 && minuteStr <= 9) {
			minuteStr = "0" + minuteStr;
		}
		if (hourStr >= 0 && hourStr <= 9) {
			hourStr = "0" + hourStr;
		}
		
		var currentdate = date.getFullYear() + seperator1 + month + seperator1
		+ strDate + " " + hourStr + seperator2 + minuteStr
		+ seperator2 + secondStr;
	    $(".times").text(currentdate);
	    setTimeout(getNowFormatDate, 1000);
	}
</script>


</html>